import Cookies from 'js-cookie'
import Vue from 'vue'
import { ACCESS_TOKEN } from '@/store/mutation-types'

const TokenKey = 'Admin-Token'

const ExpiresInKey = 'Admin-Expires-In'

export function getToken() {
  return Vue.ls.get(ACCESS_TOKEN)
  // return Cookies.get(TokenKey)
}

export function setToken(token) {
  return  Vue.ls.set(ACCESS_TOKEN, token, 6 * 60 * 60 * 1000)
  // return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Vue.ls.remove(ACCESS_TOKEN)
  // return Cookies.remove(TokenKey)
}

export function getLs(key) {
  return Vue.ls.get(key)
}
export function setLs(key, val, expire = 6 * 60 * 60 * 1000) {
  return Vue.ls.set(key, val, expire)
}
export function removeLs(key) {
  return Vue.ls.remove(key)
}
// 清楚所有storage
export function clearLs() {
  return Vue.ls.clear()
}


export function getExpiresIn() {
  return Cookies.get(ExpiresInKey) || -1
}

export function setExpiresIn(time) {
  return Cookies.set(ExpiresInKey, time)
}

export function removeExpiresIn() {
  return Cookies.remove(ExpiresInKey)
}
